//<script type="text/javascript">
    function docReady(ajaxDiv)
    {
        // Tabs
        $(ajaxDiv).tabs({
            fx: {
                //height: "toggle",
                opacity: "toggle",
                duration: "slow",
            //easing: "linear",
            }
        });
    }

    function setupLinks(ajaxDiv)
    {
        $(ajaxDiv+' #itemLink').click(function(){
            var search = $(this).text();
            var itemid = $(this).attr('rel');
            $('#itemDialog').dialog('option', 'title', $(this).parent().html());
            $('#itemDialog').dialog('option', 'height', 200);
            $('#itemDialog').dialog('option', 'width', 400);

            if (!$('#itemDialog').dialog('isOpen'))
                $('#itemDialog').dialog('open');
            $.ajax({
                method: "get",
                url: "<?php echo url_for('ajax/item') ?>",
                data: {
                    s: search,
                    i: itemid
                },
                beforeSend: function()
                {
                    $("#itemDialog").html("");
                    $('#ajaxLoader').appendTo("#itemDialog").css({
                        position: "relative",
                        top: "0px",
                        left: "0px"
                    });
                },
                success: function(data, textStatus)
                {
                    $("#ajaxLoader").appendTo("body").css({
                        position: "relative",
                        top: "0px",
                        left: "0px"
                    });
                    $("#itemDialog").html(data);
                    docReady("#itemDialog");
                }
            });
            return false;
        });

        $(ajaxDiv+' #historyLink').click(function()
        {
            var search = $(this).attr('data');
            $('#historyDialog').dialog('option', 'title', 'History of '+search);
            $('#historyDialog').dialog('option', 'height', 200);
            $('#historyDialog').dialog('option', 'width', 400);

            if (!$('#historyDialog').dialog('isOpen'))
                $('#historyDialog').dialog('open');
            $.ajax({
                method: "get",
                url: "<?php echo url_for('ajax/history') ?>",
                data: {
                    s: search
                },
                beforeSend: function()
                {
                    $("#historyDialog").html("");
                    $('#ajaxLoader').appendTo("#historyDialog").css({
                        position: "relative",
                        top: "0px",
                        left: "0px"
                    });
                },
                success: function(data, textStatus)
                {
                    $("#ajaxLoader").appendTo("body").css({
                        position: "relative",
                        top: "0px",
                        left: "0px"
                    });
                    $("#historyDialog").html(data);
                    docReady("#historyDialog");
                }
            });
            return false;
        });

        //hover states on the static widgets
        $(ajaxDiv+' span#points, '+ajaxDiv+' span#attendance, '+ajaxDiv+' span#talent, '+ajaxDiv+' .ui-allow-hover').hover(
        function() { $(this).addClass('ui-state-hover'); },
        function() { $(this).removeClass('ui-state-hover');
        });

        $(ajaxDiv+' tr.ui-allow-hover').hover(
        function() { $(this).children().addClass('ui-state-hover'); },
        function() { $(this).children().removeClass('ui-state-hover');
        });

        $(ajaxDiv+" .pager").click(function()
        {
            //alert($(this).attr('loc')+$(this).attr('href'));
            var loc = $(this).attr('loc');
            $.ajax({
                method: "get",
                url: $(this).attr('href'),
                beforeSend: function()
                {
                    $("#ajaxLoader").appendTo("body").css({
                        position: "absolute",
                        top: "75%",
                        left: "50%",
                        margin: "-"+$("#ajaxLoader").width()/2+"px"
                    });
                },
                success: function(data, textStatus)
                {
                    $("#ajaxLoader").appendTo("body").css({
                        position: "absolute",
                        top: "75%",
                        left: "50%",
                        margin: 0
                    });
                    $("#"+loc).html(data);
                    setupLinks("#"+loc);
                }
            });
            return false;
        });

        $(ajaxDiv+" #pagination th").click(function()
        {
            //alert($(this).attr('loc')+$(this).attr('href'));
            if ($(this).attr('href') == undefined)
                return;
            var loc = $(this).attr('loc');
            $.ajax({
                method: "get",
                url: $(this).attr('href'),
                beforeSend: function()
                {
                    $("#ajaxLoader")
                    $("#ajaxLoader").appendTo("body").css({
                        position: "absolute",
                        top: "50%",
                        left: "50%",
                        marginLeft: "-"+$("#ajaxLoader").width()/2+"px"
                    });
                },
                success: function(data, textStatus)
                {
                    $("#ajaxLoader").appendTo("body").css({
                        position: "relative",
                        top: "0px",
                        left: "0px",
                        margin: 0
                    });
                    $("#"+loc).html(data);
                    setupLinks("#"+loc);
                }
            });
            return false;
        });
    }
//</script>